package com.ymttest.business.service;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.ymatou.api.marketingseller.service.CancelOrEndPromotionCall;
import com.ymatou.api.marketingseller.service.CreateSellerPromotionCall;
import com.ymatou.iapi.couponactivity.parameter.NewUserMobileBoundBean;
import com.ymatou.iapi.sellerproduct.parameter.CatalogLevelBean;
import com.ymatou.iapi.sellerproduct.service.ActivityProductStartSaleCall;
import com.ymatou.iapi.sellerproduct.service.ActivityProductSuspendSaleCall;
import com.ymatou.iapi.sellerproduct.service.AddFbxProductCall;
import com.ymatou.iapi.sellerproduct.service.AddNewSellerProductCall;
import com.ymatou.iapi.sellerproduct.service.AddProductInLivesCall;
import com.ymatou.iapi.sellerproduct.service.BatchSetProductOffSaleCall;
import com.ymatou.iapi.sellerproduct.service.ChangeNewProductInfoCall;
import com.ymatou.iapi.sellerproduct.service.GetSetTopProductsCall;
import com.ymatou.iapi.sellerproduct.service.QuerySellerProductListCall;
import com.ymatou.iapi.sellerproduct.service.SetTopProductCall;
import com.ymt.core.tool.Logger;
import com.ymttest.database.model.YmtProductsI;
import com.ymttest.database.model.YmtProductsInActivity;
import com.ymttest.database.model.YmtProductsInLive;
import com.ymttest.database.model.YmtSellerPromotion;
import com.ymttest.database.mongo.ProductBasicInfoWapper;
import com.ymttest.database.mongo.ProductDetailModelWapper;
import com.ymttest.database.mongo.ProductListingModelWapper;
import com.ymttest.database.mongo.YmtMongoDriverFactroy;
import com.ymttest.database.sqlwapper.YmtProductCategoryWapper;
import com.ymttest.database.sqlwapper.YmtProductPictureWapper;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import com.ymttest.database.sqlwapper.YmtProductsInActivityWapper;
import com.ymttest.database.sqlwapper.YmtProductsInLiveWapper;
import com.ymttest.database.sqlwapper.YmtSellerPromotionIMapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.JsonBeanHelper;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.JsonBeanFile;


public class SellerPromotionCallService {
	
	
	/*
	 *  检查是否存在满减促销活动，若存在，则取消
	 */
	public static void checkIsExistPromotion(Integer sellerID) throws InterruptedException, JSONException{
		// 校验是否存在未开始或已开始的满减活动，若存在，则取消
		List<YmtSellerPromotion> sellerPromotionIDlist = new YmtSellerPromotionIMapper().selectPromotionBySellerId(sellerID);
		if(sellerPromotionIDlist.size() > 0){
			for(int i=0;i<sellerPromotionIDlist.size();i++){
				Map<String,Object> promotionIdmap= new HashMap<String,Object>();
				promotionIdmap.put("PromotionId",sellerPromotionIDlist.get(i).getPromotionId());
				promotionIdmap.put("SellerId",20323743);
				if(sellerPromotionIDlist.get(i).getPromotionState() == 0){
					promotionIdmap.put("OperatorType",1);
				} else{
					promotionIdmap.put("OperatorType",2);
				}
				
				JSONObject CancelOrEndPromotionretBea = new CancelOrEndPromotionCall().callAndGetReturnData(promotionIdmap);
				boolean flag = CancelOrEndPromotionretBea.getJSONObject("Data").getBoolean("IsSuccess");
				Logger.verifyEquals(true, flag, "验证促销活动是否成功取消");
				
				int code =CancelOrEndPromotionretBea.getInt("Code");
				Logger.verifyEquals(200, code, "code是否等于200");
				
			}
		}else{
		}
		
	}
	
	/*
	 * 创建未开始和进行中的满减促销
	 */
	public static void Create3Promotions() throws InterruptedException, JSONException{
		// 校验是否存在未开始或已开始的满减活动，若存在，则取消
		// 未开始的活动
		Map<String,Object> Firstmap = new HashMap<String,Object>();
		Firstmap.put("PromotionInfo->PromotionName","满2件减8.8-自动");
		Firstmap.put("PromotionInfo->PromotionBeginTime",YMTDateUtil.getBeforeOrNextDay(1));
		Firstmap.put("PromotionInfo->PromotionEndTime",YMTDateUtil.getBeforeOrNextDay(3));
		Firstmap.put("PromotionInfo->PromotionType","1");
		Firstmap.put("PromotionInfo->IsSpecifyProduct",true);
		Firstmap.put("PromotionInfo->ProductIds",new JSONArray("[bf92baaa-acb2-4de7-bb2d-792a5322bc02,f0e7200f-2577-4a24-8d3b-45e76f7ab527]"));
		new CreateSellerPromotionCall().callAndGetReturnData(Firstmap);
		
		Map<String,Object> Secondmap = new HashMap<String,Object>();
		Secondmap.put("PromotionInfo->PromotionName","满2件减9.8-自动");
		Secondmap.put("PromotionInfo->PromotionBeginTime",YMTDateUtil.getBeforeOrNextDay(0));
		Secondmap.put("PromotionInfo->PromotionEndTime",YMTDateUtil.getBeforeOrNextDay(3));
		Secondmap.put("PromotionInfo->PromotionType","2");
		Secondmap.put("PromotionInfo->IsSpecifyProduct",true);
		Secondmap.put("PromotionInfo->ProductIds",new JSONArray("[f1e49483-7fb0-4246-acc8-a785b9f1d713]"));
		new CreateSellerPromotionCall().callAndGetReturnData(Secondmap);
		
		Map<String,Object> Thirdmap = new HashMap<String,Object>();
		Thirdmap.put("PromotionInfo->PromotionName","满2件减8.8-自动");
		Thirdmap.put("PromotionInfo->PromotionBeginTime",YMTDateUtil.getBeforeOrNextDay(0));
		Thirdmap.put("PromotionInfo->PromotionEndTime",YMTDateUtil.getBeforeOrNextDay(3));
		Thirdmap.put("PromotionInfo->PromotionType","1");
		Thirdmap.put("PromotionInfo->IsLimitProduct",true);
		new CreateSellerPromotionCall().callAndGetReturnData(Thirdmap);
		
	}

	public void CreateSellerPromotion(HashMap promotionMap) throws InterruptedException, JSONException{
		
		
		JSONObject SellerPromotionBean = new CreateSellerPromotionCall().callAndGetReturnData(promotionMap);
		NewUserMobileBoundBean newusermobileboundBean = new NewUserMobileBoundBean();
		//return SellerPromotionBean;
		
	}
	
	public static void main(String[] args) throws Exception {

	}
}
